package com.wx.plugin.mvc;

import com.wx.plugin.mp.core.OrderRequestVO;
import com.wx.plugin.mp.core.OrderVO;
import com.wx.plugin.mp.core.OrderVOResult;
import com.wx.plugin.mp.core.WXAPI;
import com.wx.plugin.repository.MembersRepository;
import com.wx.plugin.util.JSONUtil;
import com.yangzcp.userpojo.Members;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
public class DebugController {
    @Autowired
    private WXAPI wxapi;

    @Autowired
    private MembersRepository membersRepository;

    @RequestMapping(value = "/debug/order/{order_id}", method = RequestMethod.GET)
    public String debugorder(@PathVariable("order_id") String order_id, HttpServletRequest request, HttpServletResponse response) {
        OrderRequestVO orderRequestVO = new OrderRequestVO();
        orderRequestVO.setOrder_id(order_id);
        String order = wxapi.getOrder(orderRequestVO);
        OrderVOResult orderVOResult = JSONUtil.parse(order, OrderVOResult.class);
        OrderVO orderVO = orderVOResult.getOrder();
        return JSONUtil.toJson(orderVO);
    }

    @RequestMapping(value = "/debug/users/{tel}", method = RequestMethod.GET)
    public String debugusers(@PathVariable("tel") String tel, HttpServletRequest request, HttpServletResponse response) {
        Members byTel = membersRepository.findByTel(tel);
        return JSONUtil.toJson(byTel);
    }
}
